{% extends 'homepage.html' %}
{% block content %}

<script>
{% if start %}
var start = {{start}};
{% else %}
var start = '';
{% endif %}

{% if end %}
var end = {{end}};
{% else %}
var end = '';
{% endif %}

{% if degree %}
var degree = {{degree}};
{% else %}
var degree = '';
{% endif %}

{% if limit %}
var limit = {{limit}};
{% else %}
var limit = 100;
{% endif %}
var startstr = "";
if(start > 0) {
    startstr = String(start);
}
var endstr = "";
if(end > 0) {
    endstr = String(end);
}
var degreestr = "";
if(degree > 0) {
    degreestr = String(degree)
}
var argstring = '?start='+startstr+"&end="+endstr+"&limit="+limit+'&degree='+degreestr;
listzeros_url = '{{url_for(".list_zeros")}}';
displayzeros_url = '{{url_for(".firstzeros")}}';
function loadzeros(save_history) {
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
        if(request.readyState == 4 && request.status == 200) {
            var zero_table = document.getElementById('zero_table');
            var old_length = zero_table.rows.length
            for(var n = 0; n < old_length - 1; n++) {
                zero_table.deleteRow(-1);
            }
            var lines = request.responseText.split('\n');
            start = Number(lines[0].split(' ')[0]);
            document.getElementById("startbox").value = start;
            var entry = ''
            for(var n = 0; n < lines.length; n++) {
                if(lines[n] == "") {
                    continue;
                }
                entry = lines[n].split(' ');
                var row = zero_table.insertRow(-1);

                var L_link = "";
                var obj_link = "";
                var description = "";
                if(entry[5] == '0'){
                    description = "Riemann zeta function";
                    L_link = "/L/Riemann/";
                    obj_link = "/L/Riemann/";
                }
                else if (entry[5] == '1'){
                    description = "Dirichlet character " + entry[6] + " modulo " + entry[2];
                    var q = Number(entry[2]);
                    if(q < 50) {
                        L_link = "/L/Character/Dirichlet/" + entry[2] + "/" + entry[6];
                        obj_link = "/Character/Dirichlet/" + entry[2] + "/" + entry[6];
                    }
                }
                else if (entry[5] == '2') {
                    description = "Elliptic curve " + entry[6];
                    L_link = "/L/EllipticCurve/Q/" + entry[6];
                    obj_link = "/EllipticCurve/Q/" + entry[6];
                }
                else {
                    description = entry[5] + ' ' + entry[6];
                }

                var cell
                cell = row.insertCell(-1);
                if(L_link == "") {
                    cell.appendChild(document.createTextNode(entry[0])); // zero
                }
                else {
                    var a = document.createElement('a');
                    a.setAttribute('href', L_link);
                    a.appendChild(document.createTextNode(entry[0]));
                    cell.appendChild(a);
                }
                cell = row.insertCell(-1);
                cell.appendChild(document.createTextNode(entry[1])); // degree
                cell = row.insertCell(-1);
                cell.appendChild(document.createTextNode(entry[2])); // level
                cell = row.insertCell(-1);
                cell.appendChild(document.createTextNode('[' + entry[3] + ',' + entry[4] + ']')); //signature
                cell = row.insertCell(-1);
                if(entry[5] == '0'){
                    description = "Riemann zeta function";
                }
                else if (entry[5] == '1'){
                    description = "Dirichlet character " + entry[6] + " modulo " + entry[2];
                }
                else if (entry[5] == '2') {
                    description = "Elliptic curve " + entry[6]
                }
                else {
                    description = entry[5] + ' ' + entry[6];
                }
                if(obj_link == "") {
                    cell.appendChild(document.createTextNode(description)); // type and label
                }
                else {
                    var a = document.createElement('a');
                    a.setAttribute('href', obj_link);
                    a.appendChild(document.createTextNode(description));
                    cell.appendChild(a);
                }
            }
            end = Number(entry[0])
            document.getElementById("endbox").value = end;
        }
    };
    startstr = "";
    if(start > 0) {
        startstr = String(start);
    }
    endstr = "";
    if(end > 0) {
        endstr = String(end);
    }
    argstring = '?start='+startstr+"&end="+endstr+"&limit="+limit+'&degree='+degreestr;
    if(save_history) {
        history.pushState({'start' : start, 'limit' : limit, 'end' : end, 'degree' : degree},
                            "zeta zeros", displayzeros_url + argstring);
    }
    document.getElementById('plainlink').href = listzeros_url + argstring;
    document.getElementById('plaindownloadlink').href = 
                              listzeros_url + argstring + '&download=yes';

    request.open('GET', listzeros_url + argstring, true);
    request.send(null);
};
function next() {
    start = end;
    end = ''
    loadzeros(true);
};
function prev() {
    end = start
    start = ''
    loadzeros(true);
};
var oldonload = window.onload;
window.onload = function() {
    if(oldonload) {
        oldonload();
    }
    loadzeros(false);
};
window.onpopstate = function(event) {
    if(event.state) {
        start = event.state.start;
        limit = event.state.limit;
        end = event.state.end;
        degree = event.state.degree
        loadzeros(false);
    }
};
</script>
<form align="center">
    List up to <input type="text" name="limit" value="{{limit}}" style="width:5em"/>
    first zeros with imaginary part between <input type="text" value="{{start}}" name="start" id="startbox"/>
    and <input type="text" value="{{end}}" name="end" id="endbox"/>.
    <br/>
    {% if degree %}
    Restrict to degree <input type="text" name="degree" value="{{degree}}" style="width:5em"/>.
    {% else %}
    Restrict to degree <input type="text" name="degree" value="" style="width:5em"/>.
    {% endif %}
    <br/>
    <button type="submit" value="Go">Go</button>
</form>
<br/>
<div align="center">
    <a id="plainlink" href="">View</a> or <a id="plaindownloadlink" href="">download</a> this table as plain text.
</div>
<br/>
<div align="center">
    {{KNOWL('zeros.first.contents', title="Contents of these tables.")}}
</div>
<br/>
<div align="center">
    <a href="#" class="navlink" onclick="prev(); return false">Previous {{limit}}</a>
    <a href="#" class="navlink" onclick="next(); return false">Next {{limit}}</a>
</div>
<table class='ntdata' id='zero_table' align="center">
    <thead><td>Zero</td><td>Degree</td><td>Level</td><td>Signature</td><td>Underlying Object</td></thead>
</table>

{% endblock %}
